﻿using MediatR;
using ProductionManagement.Application.Command.StrippingCommand;
using ProductionManagement.Infrstructre.lnterface;

namespace ProductionManagement.Application.CommandHandler.StrippingCommandHandler
{
    public class DelStrippingProductCommandHandler : IRequestHandler<DelStrippingProductCommand, int>
    {
        IStripProductRepostory spRep;

        public DelStrippingProductCommandHandler(IStripProductRepostory spRep)
        {
            this.spRep = spRep;
        }

        public async Task<int> Handle(DelStrippingProductCommand request, CancellationToken cancellationToken)
        {
            var list = (await spRep.GetAll()).Where(c => request.StripProductId.Contains(c.StripProductId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelTime = DateTime.Now;
                await spRep.UpdAsync(item);
            }
            return 1;
        }
    }
}
